package com.dede.monochromatism.activity

import android.annotation.SuppressLint
import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import com.dede.monochromatism.base.BaseActivity
import org.jetbrains.anko.matchParent
import org.jetbrains.anko.webView

/**
 * @author hsh
 * @date 2017/9/19 19:28.
 * @doc
 */
class AboutActivity : BaseActivity() {

    @SuppressLint("SetJavaScriptEnabled", "JavascriptInterface")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        showBackButton(true)

        val packageInfo = packageManager.getPackageInfo(packageName, 0)
        webView {
            lparams(matchParent, matchParent)
            settings.javaScriptEnabled = true

            loadUrl("file:///android_asset/about.html")

            setWebChromeClient(object : WebChromeClient() {
                override fun onProgressChanged(view: WebView, newProgress: Int) {
                    if (newProgress == 100)
                        view.loadUrl("javascript:setVersion('${packageInfo.versionName} (${packageInfo.versionCode})')")
                }
            })
        }
    }

}